package 树;

public class Leedcode110平衡二叉树 {
    public boolean isBalanced(TreeNode root) {
        if (root == null){
            return true;
        }
        int left = heightest(root.left);
        int right = heightest(root.right);
        return Math.abs(left - right) <= 1 && isBalanced(root.left) && isBalanced(root.right);
    }
    public int heightest(TreeNode root){
        return root == null ? 0 : 1 + Math.max(heightest(root.left),heightest(root.right));
    }
}
